package com.qcby.admin.controller;


import com.qcby.admin.form.AddArticleForm;
import com.qcby.admin.form.ArticleForm;
import com.qcby.admin.model.SgArticle;
import com.qcby.admin.service.SgArticleService;


import com.qcby.admin.vo.ArticleVo;
import com.qcby.admin.vo.HotArticleVO;
import com.qcby.admin.vo.PageVo;
import com.qcby.framwork.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 文章表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2024-09-08
 */
@RestController
@RequestMapping("/content/article")
public class SgArticleController {
    @Autowired
    private SgArticleService sgArticleService;


    /**
     * 文章分页
     * @param article
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public ResponseResult list(SgArticle article, Integer pageNum, Integer pageSize)
    {
        PageVo pageVo = sgArticleService.selectArticlePage(article,pageNum,pageSize);
        return ResponseResult.okResult(pageVo);
    }
    @PostMapping
    public ResponseResult add(@RequestBody AddArticleForm article){
        return sgArticleService.add(article);
    }

    @GetMapping(value = "/{id}")
    public ResponseResult getInfo(@PathVariable(value = "id")Long id){
        ArticleVo article = sgArticleService.getInfo(id);
        return ResponseResult.okResult(article);
    }

    @PutMapping
    public ResponseResult edit(@RequestBody ArticleForm article){
        sgArticleService.edit(article);
        return ResponseResult.okResult();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id){
        sgArticleService.removeById(id);
        return ResponseResult.okResult();
    }
    @GetMapping("/chart1")//图表一 ：热门文章的访问量
    public ResponseResult hotCount(){
        HotArticleVO hotArticleVO = sgArticleService.hotcount();
        return ResponseResult.okResult(hotArticleVO);
    }

    @GetMapping("/chart2")//图表2 ：各个分类数量
    public ResponseResult categorycount(){
        List<Map<String, String>> categoryMapVos = sgArticleService.categorycount();
        return ResponseResult.okResult(categoryMapVos);
    }
    @GetMapping("/chart3")//图表2 ：各个分类数量
    public ResponseResult usercount(){
        List<Map<String, String>> userMapVos = sgArticleService.usercount();
        return ResponseResult.okResult(userMapVos);
    }


}

